package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.Springboot01Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class springboot01Controller {
    @Autowired
    Springboot01Service weekService;
    @RequestMapping("sumTotal")
    public Object sumTotal() {
        List<Map> maps = weekService.sumTotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",maps.get(0).get("sum"));
        return jsonObject;
    }

    @RequestMapping("proTotal")
    public Object proTotal() {
        List<Map> maps = weekService.proTotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject mapObject = new JSONObject();
        JSONArray mapArray = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("price"));
            mapArray.add(jsonObject1);
        }
        mapObject.put("mapData",mapArray);
        jsonObject.put("data",mapObject);
        return jsonObject;
    }
}
